package com.ztr.designpatterns.singleton;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Bowl {

    //私有静态成员变量，存储唯一实例
    private static Bowl instance = null;

    //人的集合
    private List personList = null;

    //私有构造函数
    private Bowl(){
        personList = new ArrayList();
    }

    //公有静态成员方法，返回唯一实例
    public static Bowl getBowl(){
        if(instance == null){
            instance = new Bowl();
        }
        return instance;
    }

    //增加吃饭的人
    public void addPerson(String person){
        personList.add(person);
    }

    //删除服务器
    public void removePerson(String person){
        personList.remove(person);
    }

    //使用Random类随机获取服务器
    public String getPerson(){
        Random random = new Random();
        int i = random.nextInt(personList.size());
        return(String)personList.get(i);
    }

}
